package com.drinkian.alipay.controller;

import com.alipay.api.AlipayApiException;
import com.drinkian.alipay.entity.vo.VOrder;
import com.drinkian.alipay.service.IALiPayService;
import com.drinkian.entity.RequestResult;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("alipay")
public class ALiPayController {

    @Autowired
    private IALiPayService iaLiPayService;

    @PostMapping("toPay")
    public RequestResult toPay(@RequestBody VOrder vOrder) throws JSONException, AlipayApiException {
        return iaLiPayService.toPay(vOrder);
    }

    @PostMapping("payCallback")
    public void payCallback(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException {
        iaLiPayService.payCallback(request, response);
    }
}
